import React,{createContext,useReducer} from "react";
import {initialInput} from '../options'


export const barContext = createContext();


const reducer = (state,action) => {
    switch (action.type) {
        case 'maxvalue':

            return {
                ...state,
                maxvalue:action.payload.value
            };
        case 'minvalue':

            return {
                ...state,
                minvalue:action.payload.value
            };
        case 'numvalue':

            return {
                ...state,
                numvalue:action.payload.value
            };
        case 'ORDER':

            return {
                ...state,
                orderValue:state.orderValue?0:1

            };
        default:
            return state;
    }
}


export default function BarContext(props) {

    const [state,dispatch] = useReducer(reducer,initialInput);


    return (
        <barContext.Provider value={{
            state,
            dispatch
        }}>
            {props.children}
        </barContext.Provider>
    )
}